#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../ourhdr.h"
/**
 * 显示相对于文件末尾的锁的问题
 * 对文件内容的字节一隔一加锁
 * 可能会因为内核锁表用完出错 No record locks available
 **/
int main(void)
{
    int i,fd;
    if((fd=open("temp.lock", O_RDWR | O_CREAT | O_TRUNC, FILE_MODE))<0)
    {
        err_sys("open error");
    }
    for(i=0;i<1000000;i++)
    {
        if(writew_lock(fd,0,SEEK_END,0) <0 )
        {
            err_sys("writew_lock error");
        }
        if(write(fd,&fd, 1) !=1)
        {
            err_sys("write[21] error");
        }

        if(un_lock(fd,0,SEEK_END, 0) <0 )
        {
            err_sys("un_lock error");
        }
        
        if(write(fd,&fd,1) !=1)
        {
            err_sys("write[31] error");
            
        }
    }
    exit(0);
}